#include <iostream>
#include <unistd.h>
#include <sys/wait.h>

using std::cout;
using std::endl;

void test()
{
    int a = 10;

    pid_t pid = fork();
    cout << "pid = " << pid << endl;
    if (pid == 0)
    {
        cout << "this is child process, the id is " << getpid() << " and the parent id is " << getppid() << endl;
        sleep(3);
        cout << "a = " << a << endl; // 10
    }
    else
    {
        cout << "parent a = " << ++a << endl;
        cout << "wait = " << wait(nullptr) << endl;
        cout << "this is parent process, the id is " << getpid() << " and the parent id is " << getppid() << endl;
    }

    sleep(3);
}

int main(int args, char *argv[])
{
    test();
    // cout << getenv("PATH") << endl;
    return 0;
}